/**
 * @author hewei
 * @version 1.0
 * @description: 1052. 爱生气的书店老板
 * @date 2022/10/24 14:34
 */

public class MaxSatisfied {

    public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
        int l = 0;
        int r = minutes - 1;
        int n = grumpy.length;
        int sum = 0;
        int ans = 0;
        for (int i = 0; i <= r; i++) {
            if (grumpy[i] == 1) {
                sum += customers[i];
            } else ans += customers[i];
        }
        int max = sum;
        ++r;
        ++l;
        while (r < n) {
            if (grumpy[l - 1] == 1) sum -= customers[l - 1];
            if (grumpy[r] == 1) {
                sum += customers[r];
            } else ans += customers[r];
            max = Math.max(max, sum);
            ++l;
            ++r;
        }
        return ans + max;
    }
}
